<template>
	<view>
		<head-children :isBack="'1'">
			<template v-slot:default="">
				<view class="time">错题查看</view>

			</template>
		</head-children>
		<view class="main" v-if="list.length>0">
			<view class="subject">
				<text class="type" v-if="!currentData.answer_c">判断题</text>
				<text class="type" v-if="currentData.answer_c && currentData.right_answer.length==1">选择题</text>
				<text class="type" v-if="currentData.answer_c && currentData.right_answer.length>1">多选题</text>
				{{currentData.questions}}
			</view>
			<view class="images" v-if="currentData.questions_image">
				<image class="img" :src="currentData.questions_image" mode="widthFix"></image>
			</view>
			<view class="answer">
				<!-- A -->
				<view class="item true" v-if="currentData.right_answer.indexOf('A')>-1">
					<text class="round">A</text>
					<text class="answer-text">{{currentData.answer_a}}</text>
				</view>
				<view class="item false" v-else-if="currentData.your_answer.indexOf('A')>-1">
					<text class="round"><u-icon name="close" color="#fff" size="28"></u-icon></text>
					<text class="answer-text">{{currentData.answer_a}}</text>
				</view>

				<view class="item" v-else>
					<text class="round">A</text>
					<text class="answer-text">{{currentData.answer_a}}</text>
				</view>
				<!-- B -->
				<view class="item true" v-if="currentData.right_answer.indexOf('B')>-1">
					<text class="round">B</text>
					<text class="answer-text">{{currentData.answer_b}}</text>
				</view>
				<view class="item false" v-else-if="currentData.your_answer.indexOf('B')>-1">
					<text class="round"><u-icon name="close" color="#fff" size="28"></u-icon></text>
					<text class="answer-text">{{currentData.answer_b}}</text>
				</view>
				<view class="item" v-else>
					<text class="round">B</text>
					<text class="answer-text">{{currentData.answer_b}}</text>
				</view>
				<!-- C -->

				<view class="item true" v-if="currentData.right_answer.indexOf('C')>-1 && currentData.answer_c">
					<text class="round">C</text>
					<text class="answer-text">{{currentData.answer_c}}</text>
				</view>
				<view class="item false" v-else-if="currentData.your_answer.indexOf('C')>-1">
					<text class="round"><u-icon name="close" color="#fff" size="28"></u-icon></text>
					<text class="answer-text">{{currentData.answer_c}}</text>
				</view>

				<view class="item" v-else>
					<text v-if="currentData.answer_c" class="round">C</text>
					<text class="answer-text">{{currentData.answer_c}}</text>
				</view>
				<!-- D -->
				<view class="item true" v-if="currentData.right_answer.indexOf('D')>-1 && currentData.answer_d">
					<text class="round">D</text>
					<text class="answer-text">{{currentData.answer_d}}</text>
				</view>
				<view class="item false" v-else-if="currentData.your_answer.indexOf('D')>-1">
					<text class="round"><u-icon name="close" color="#fff" size="28"></u-icon></text>
					<text class="answer-text">{{currentData.answer_d}}</text>
				</view>

				<view class="item" v-else>
					<text v-if="currentData.answer_d" class=" round">D</text>
					<text class="answer-text">{{currentData.answer_d}}</text>
				</view>
			</view>
			<view class="detail">
				<view class="line">
					<view class="left"></view> 试题详解 <view class="left"></view>
				</view>
				<view class="standard">
					标准答案：{{this.currentData.explain}}
				</view>
			</view>
			<view class="bottom">
				<view class="item" @click="prev">
					<u-icon name="arrow-left"></u-icon>上一题
				</view>
				<view class="number" style="color: #4365C6;">
					<text class="round"> <u-icon name="checkmark"></u-icon></text>0
				</view>
				<view class="number" style="color:#9A2925">
					<text class="round"> <u-icon name="close"></u-icon></text>0
				</view>
				<view class="item">
					<u-icon color="#3584FA" name="grid"></u-icon>{{currentIndex+1}}/{{count}}
				</view>
				<view class="item" @click="nextSubject">
					下一题 <u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		orderPractice,
		errorRecord,
		nextSubjectApi
	} from "@/api/index.js"
	import headChildren from '../../components/head.vue';
	export default {
		components: {
			headChildren
		},
		data() {
			return {
				count: '',
				class: '',
				quest: '',
				subjectType: '',
				isTrue: true,
				explain: '',
				isAnswer: true,
				correct: '',
				error: '',
				thisNum: 1,
				currentData: '',
				size: 1,
				page_size: 10,
				list: [],
				currentIndex: 0,
				subject: '1'
			};
		},
		mounted() {},
		onLoad(option) {
			let isVip = option.isVip
			if (isVip == 'true') {
				this.subject = uni.getStorageSync("vipSubject")
			} else {
				this.subject = uni.getStorageSync("subjectType")
			}

			this.getSubject()
		},
		methods: {
			//获取错题
			getSubject() {
				let params = {
					page: this.size,
					page_size: this.page_size,
					subject: this.subject
				}
				errorRecord(params).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data.list)
						if (this.size == 1) {
							this.currentData = this.list[0]
						}

						this.count = res.data.count
						console.log(this.currentData)
					}
				})
			},
			//上一题
			prev() {
				if (this.currentIndex === 0) {
					uni.showToast({
						title: '已经是第一题了',
						icon: 'none'
					})
					return
				}
				this.currentIndex--
				this.currentData = this.list[this.currentIndex]
			},
			//下一题
			nextSubject() {
				if (this.currentIndex + 1 >= this.list.length) {

					uni.showToast({
						title: '已经到最后一题了',
						icon: 'none'
					})
					return
				}
				this.currentIndex++
				if (this.currentIndex + 2 == this.list.length) {
					this.size++
					this.getSubject()
				}

				this.currentData = this.list[this.currentIndex]
			}
		}
	}
</script>

<style lang="scss">
	.time {
		color: #fff;
	}

	.main {
		background-color: #fff;
		padding: 26rpx;
		padding-bottom: 100rpx;

		.confirm {
			font-size: 28rpx;
			color: #fff;
			background-color: #4394ED;
			position: fixed;
			right: 40rpx;
			bottom: 20%;
			border-radius: 100%;
			width: 100rpx;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
		}

		.subject {
			font-size: 30rpx;
			color: #666;
			line-height: 40rpx;

			.type {
				color: #597CD6;
				border: 1px solid #597CD6;
				font-size: 28rpx;
				border-radius: 10rpx;
				padding: 2rpx 10rpx;
				margin-right: 10rpx;
			}
		}

		.images {
			margin-top: 40rpx;
			text-align: center;
			width: 100%;

			.img {
				max-width: 80%;
			}
		}

		.detail {
			margin-top: 40rpx;

			.line {
				display: flex;
				font-size: 28rpx;
				color: #C6362E;
				align-items: center;

				.left {
					border-bottom: 1px dotted #C6362E;
					height: 1px;
					flex: 1;
				}
			}

			.standard {
				color: #5F5F5F;
				font-size: 28rpx;
				margin-top: 20rpx;
			}
		}

		.answer {

			font-size: 30rpx;
			color: #000;

			.item {
				margin-top: 40rpx;
				display: flex;
				flex-wrap: wrap;

				.round {
					width: 45rpx;
					height: 45rpx;
					border-radius: 100%;
					border: 1px solid #333;
					display: block;
					text-align: center;
					line-height: 40rpx;
					margin-right: 10rpx;
				}

				.answer-text {
					flex: 1
				}

				.selected {
					background-color: #333;
					color: #fff;
				}
			}

			.true {


				.round {
					background-color: #4394ED;
					color: #fff;
					border: 1px solid #4394ED;
				}
			}

			.false {


				.round {
					background-color: #D22E25;
					color: #fff;
					border: 1px solid #D22E25;
				}
			}
		}

		.other {
			display: flex;
			align-items: center;
			margin-top: 40rpx;

			.item {
				margin-right: 20rpx;
				color: #646464;
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
				border: 1px solid #646464;
			}
		}

		.skill {
			margin-top: 40rpx;
			color: #333;
			line-height: 40rpx;
			font-size: 28rpx;
		}

		.bottom {
			position: fixed;
			bottom: 0;
			left: 0;
			background-color: #fff;
			display: flex;
			align-items: center;
			width: 100%;
			padding: 20rpx 10rpx;
			color: #5A5A5A;
			max-width: 500px;

			.item {
				flex: 1;
			}

			.number {
				flex: 1;

				.round {
					border: 1px solid #ccc;
					padding: 0 6rpx;
					margin-right: 4rpx;
				}
			}
		}
	}

	@media (min-width:500px) {
		.main {
			.bottom {
				margin-left: -250px;
				left: 50%;

			}
		}

	}
</style>